Stub Article
This article needs more information, clarification, or completion.
You can help us by expanding this article. There may be more information on its talk page.
This page is about custom blocks. For How to Add Block Help to Custom Blocks, see How to Add Block Help to Custom Blocks.
Custom Blocks are blocks which are not primitive but are rather made by using primitive or other custom blocks. The ability of making custom blocks is one of the main features of Snap! and was the main feature of BYOB (BYOB stands for Build Your Own Blocks). You can make your own commands, reporters, and predicates with this feature. However, it is not possible to make custom hat blocks, even though they have easy workarounds, such as the when <>
block.
To make custom blocks, you need to write a name for it at first. This article will show you how to make a block that will make sprites bounce. Click the Make a Block button to write the name for your custom block.
Your custom blocks will not do anything if there is no code for it. After all, it will work like a seperate program. As such, you must use other blocks to make it. For this block, you will have to insert this code- point in direction ((direction) - (180))
In case you want the results to vary (say you want squares of different size), click the plus symbols (if you turn on Plain prototype labels, you may need to wait for it to appear). You will now get the option to name an input. If you click the small arrow next to "Input name", you'll get a lot of options. Clicking the cog icon, you should see a little more options. You also get the choice to have a single input or multiple inputs.
Input | Used for | Example Use |
---|---|---|
Object | Costumes, sounds, sprites | (copy of costume @turtle :: looks) |
Text | Plain text, not anything else | error [Error!] :: control |
List | Lists | (@flash assoc @list :: list) |
Number | Numbers, not text | move (10) steps |
Any type | Anything | say [] |
Boolean (T/F) | True or false | <not <>> |
Command (inline) | Command block ring | |
Reporter | Reporter ring | (multimap (() @addInput) over @list @delInput @verticalEllipsis @addInput :: list) |
Predicate | Predicate ring | (sort @list using (<> @addInput) :: list) |
Command (C-shape) |
| |
Any (unevaluated) | (if <> then [] else []) | |
Boolean (unevaluated) |
|
You can also put upvars into your blocks. Upvars are variables that can be accessed both inside and outside the block. It can be used to make commands that can report.
An example of a block that has an upvar:
for ((i)) = (1) to (10) { }
If you click "options", you can type the options that will be available in a dropdown.
If you click "read only", the input will be darker and you can't type in, blocks must be inserted in.
If you click "static", blocks cannot be inserted into that input.
Menus gives various options that change by itself automatically.
Menu | Includes | Example Use |
---|---|---|
messages | Broadcasts | broadcast [ V] @addInput |
objects | All the sprites and stage, excluding itself | (object [ V]) |
data types[upcoming in 10.0] | List of data types, such as text, numbers and procedures | <is [] a [number V] ?> |
costumes | The costumes that the sprite has | switch to costume [ V] |
sounds | The sounds that the sprite has | play sound [ V] |
variables | set [ V] to [] | |
piano keyboard | Shows a piano keyboard that you use to select a note. | play note (60 v) for () beats |
360° dial | A dial for selecting a direction. | point in direction ( v) |
destinations[upcoming in 10.0] | Possible destinations that a sprite can go to, includes a random position, the mouse-pointer and the center | go to [ V] |
locations[upcoming] | Mouse-pointer, myself, other sprites | |
keys[upcoming] | Keyboard keys | <key [ V] pressed? |
objects + self[upcoming] | ||
sprites + self[upcoming] | ||
collidables[upcoming] | Mouse-pointer, edge, pen trails and other sprites | <touching [ V] ? |
object attributes[upcoming] | (my [ V]) | |
properties[upcoming] | ||
scenes[upcoming] | switch to scene [ V] @addInput | |
microphone[upcoming] | Microphone properties | (microphone [ V]) |
primitives[upcoming] | Primitive functions | |
extensions[upcoming] | Extension functions | extension [ V] [] @delInput @verticalEllipsis @addInput |
If you click special, you get special inputs.
Input | Description | Example Use |
---|---|---|
multi-line | Text input that allows multiple lines |
|
code | Used for anything related to code, functions the same as multi-line but monospace | |
color[upcoming] | (color [#ff0000] :: pen) | |
variables[upcoming] | Multiple upvars | script variables ((a)) @addInput |
receivers[upcoming] | Expands to "to _", then "to _ with data" | broadcast [ V] @addInput |
send data[upcoming] | Like receivers, but the broadcast dropdown is not read-only. Intended for cross-scene broadcasts. | |
conditionals[upcoming] | Can be expanded into C-shape branches with Booleans |